<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: appHeader"></head>
<body id="history-body" ontouchstart>
<div class="weui-form-preview">
    <div class="weui-form-preview__hd">
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">转序类型</label>
            <b class="weui-form-preview__item" style="float: left" th:if="${tran.type == 1}">制作件</b>
            <b class="weui-form-preview__item" style="float: left" th:if="${tran.type == 2}">装配件</b>
            <b class="weui-form-preview__item" style="float: left" th:if="${tran.type == 3}">返修票</b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">生产令号</label>
            <b class="weui-form-preview__item" style="float: left" th:text="${tran.prodNo}">2020F058-01</b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">图号</label>
            <p class="weui-form-preview__item" style="word-break:normal;
                                                      white-space:pre-warp;
                                                      word-wrapL:break-word;
                                                      width: 250px;
                                                      float: left!important;
                                                      font-weight:bold;
                                                      text-align:justify;
                                                      text-justify:inter-ideograph;"
               th:text="${tran.drawNo}"></p>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">零件名称</label>
            <b class="weui-form-preview__item" style="float: left" th:text="${tran.drawName}">钢板 44×44×20</b>
        </div>
        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">零件数量</label>
            <b class="weui-form-preview__item" style="float: left" th:text="${tran.drawNum}">10</b>
        </div>
    </div>
</div>
<h2 style="margin-top: 16px;text-align: center" th:text="${content}"></h2>
<div class="weui-cells" th:if="${content  == null or content  == '' }">
    <div>
        <div class="weui-form-preview__bd">
            <form>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">工艺路线</label>
                    <b class="weui-form-preview__item" th:if="${tran.type != 3}" style="float: left"
                       th:text="${tran.route}+'    '+${tran.orderNo}"></b>
                    <b class="weui-form-preview__item" th:if="${tran.type == 3}" style="float: left">
                        <input type="text"
                               name="route"
                               id="route"
                               maxlength="255"
                               style="width: 60px"
                               oninput="controlInputCharacters(this)"/><span style="color: red;margin-left: 10px;">不可填写转储或参焊</span>
                    </b>
                </div>
                <div class="weui-form-preview__item" th:if="${tran.transMode == 2}">
                    <label class="weui-form-preview__label">工艺工序</label>
                    <b class="weui-form-preview__item" th:if="${tran.type != 3}" style="float: left"
                       th:text="${tran.process} + '    '+${tran.handNo}"></b>
                    <b class="weui-form-preview__item" th:if="${tran.type == 3}" style="float: left">
                        <input type="text"
                               style="width: 60px"
                               name="process"
                               id="process"
                               maxlength="255"/>
                    </b>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">申请数量</label>
                    <b class="weui-form-preview__item" style="float: left">
                        <div class="weui-count">
                            <a class="weui-count__btn weui-count__decrease" th:if="${tran.type != 3}"></a>
                            <input id="trans_num" class="weui-count__number" type="number" name="num"
                                   th:data="${tran.mayApplyNum}" th:value="${tran.mayApplyNum}"
                                   onchange="changeDefVal()"/>
                            <a class="weui-count__btn weui-count__increase" th:if="${tran.type != 3}"></a>
                        </div>
                    </b>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">设备号</label>
                    <b class="weui-form-preview__item" style="float: left">
                        <input type="text" name="equNo" maxlength="255"/>
                    </b>
                </div>
                <div style="display: none">
                    <input name="prodNo"
                           th:value="${tran.prodNo}"
                           type="hidden"
                           style="display: none"/>
                    <input name="proName"
                           th:value="${tran.proName}"
                           type="hidden"
                           style="display: none"/>
                    <input name="proNum"
                           th:value="${tran.proNum}"
                           type="hidden"
                           style="display: none"/>
                    <input name="proUnit"
                           th:value="${tran.proUnit}"
                           type="hidden"
                           style="display: none"/>
                    <input name="special"
                           th:value="${tran.special}"
                           type="hidden"
                           style="display: none"/>
                    <input name="partId"
                           th:value="${tran.partId}"
                           type="hidden"
                           style="display: none"/>
                    <input name="part"
                           th:value="${tran.part}"
                           type="hidden"
                           style="display: none"/>
                    <input name="drawNo"
                           th:value="${tran.drawNo}"
                           type="hidden"
                           style="display: none"/>
                    <input name="drawName"
                           th:value="${tran.drawName}"
                           type="hidden"
                           style="display: none"/>
                    <input name="drawNum"
                           th:value="${tran.drawNum}"
                           type="hidden"
                           style="display: none"/>
                    <input name="route"
                           th:if="${tran.type != 3}"
                           th:value="${tran.route}"
                           type="hidden"
                           style="display: none"/>
                    <input name="orderNo"
                           th:if="${tran.type != 3}"
                           th:value="${tran.orderNo}"
                           type="hidden"
                           style="display: none"/>
                    <input name="process"
                           th:if="${tran.type != 3}"
                           th:value="${tran.process}"
                           type="hidden"
                           style="display: none"/>
                    <input name="orderNum"
                           th:if="${tran.type != 3}"
                           th:value="${tran.orderNum}"
                           type="hidden"
                           style="display: none"/>
                    <input name="transMode"
                           th:value="${tran.transMode}"
                           type="hidden"
                           style="display: none"/>
                    <input name="type"
                           th:value="${tran.type}"
                           type="hidden"
                           style="display: none"/>
                    <input name="sheetId"
                           th:value="${tran.sheetId}"
                           type="hidden"
                           style="display: none"/>
                    <input name="routeId"
                           th:value="${tran.routeId}"
                           type="hidden"
                           style="display: none"/>
                    <input name="processId"
                           th:value="${tran.processId}"
                           type="hidden"
                           style="display: none"/>
                </div>
                <div class="button_sp_area" style="text-align: center; margin-top: 50px;">
                    <a href="javascript:void(0);" class="weui-btn weui-btn_mini weui-btn_primary btn-apply">申请质检</a>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="weui-tabbar">
    <a th:href="@{/index}" class="weui-tabbar__item weui-bar__item--on">
        <div class="weui-tabbar__icon">
            <img th:src="@{/img/me.png}" alt="">
        </div>
        <p class="weui-tabbar__label">我的信息</p>
    </a>
    <!--生产历史-->
    <a th:if="${#strings.contains(session.user.roles,'【申请质检】')}" th:href="@{/hisApply/null/null}"
       class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <img th:src="@{/img/his_apply.png}" alt="">
        </div>
        <p class="weui-tabbar__label">历史申请</p>
    </a>
    <a th:if="${#strings.contains(session.user.roles,'【转序接收】')}" th:href="@{/hisRec/null/null}"
       class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <img th:src="@{/img/his_rec.png}" alt="">
        </div>
        <p class="weui-tabbar__label">历史接收</p>
    </a>
    <a th:if="${#strings.contains(session.user.roles,'【转序质检】')}" th:href="@{/hisCheck/null/null}"
       class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <img th:src="@{/img/his_check.png}" alt="">
        </div>
        <p class="weui-tabbar__label">历史质检</p>
    </a>
    <a th:if="${#strings.contains(session.user.roles,'【入库质检】')}" onclick="tips()" href="javascript:void(0)"
       class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <img th:src="@{/img/his_check.png}" alt="">
        </div>
        <p class="weui-tabbar__label">入库历史质检</p>
    </a>
</div>
<a id="jumpPage" style="display: none" th:href="@{/index}"/>
<div th:include="include :: appFooter"></div>
<script th:inline="javascript">
    let transType = [[${tran.type}]]
    $(function () {
        $('.weui-count__decrease').click(function (e) {
            let $input = $(e.currentTarget).parent().find('.weui-count__number');
            let number = parseInt($input.val() || "0") - 1
            if (number < 1) {
                number = 1;
            }
            $input.val(number)
        })

        $('.weui-count__increase').click(function (e) {
            let $input = $(e.currentTarget).parent().find('.weui-count__number');
            let max = $input.attr("data");
            let number = parseInt($input.val() || "0") + 1
            if (number > max) {
                number = max;
            }
            $input.val(number)
        })
        $('.btn-apply').click(function (e) {
            if (transType == '3') {
                if ($("#route").val() == "" || $("#process").val() == "") {
                    $.box.toptip_w("工艺路线和工艺工序是必填项");
                    return;
                }
            }
            $(".btn-apply").hide();
            let $form = $(e.currentTarget).parents("form");
            let formData = new FormData($form[0]);
            $.operate.submit({
                url: ctx + 'apply',
                data: formData,
                fun: function (res) {
                    if (res.type === 'SUCCESS') {
                        $.box.toptip_s(res.msg);
                        document.getElementById("jumpPage").click();//模拟点击
                    } else {
                        $.box.toptip_w(res.msg);
                    }
                }
            });
        })

    })

    /**
     * 更改数量函数
     * 徐一贺
     */
    function changeDefVal() {
        let max = document.getElementById("weui-count__number").getAttribute("data")
        let number = document.getElementById("weui-count__number").value;
        if (parseInt(number) < 1) {
            number = 1;
        }
        if (parseInt(number) > parseInt(max)) {
            number = max;
        }
        document.getElementById("weui-count__number").value = number;
    }

    /**
     * 控制显示字符 不可输入转储或参焊
     * @param obj 被控制HTML元素
     */
    function controlInputCharacters(obj) {
        let inputValue = obj.value;
        inputValue = inputValue.trim();
        if (inputValue === '参焊') {
            obj.value = '';
            $.box.toptip_w("工艺路线不可填写参焊");
        }
        if (inputValue === '转储') {
            obj.value = '';
            $.box.toptip_w("工艺路线不可填写转储");
        }
    }
</script>
</body>
</html>